package gang.org.springframework.framework.io;

import gang.org.springframework.framework.util.GangStringUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * @Author：gang.chen
 * @Date：2023/2/8 13:44
 */
public class GangFileSystemResource extends GangAbstractResource implements GangWritableResource {

    private final String path;

    private final File file;

    private final Path filePath;


    public GangFileSystemResource( File file) {
        this.path = GangStringUtils.cleanPath(file.getPath());
        this.file = file;
        this.filePath = file.toPath();
    }


    @Override
    public InputStream getInputStream() {
        try {
            return Files.newInputStream(this.filePath);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public String getDescription() {
        return null;
    }
}
